export const queue = [];
let isFlusing = false;
const resolvePromise = Promise.resolve();

export const queueJob = job => {
  if (!queue.includes(job)) {
    queue.push(job);
  }
  if (!isFlusing) {
    isFlusing = true;
    // 等待数据全部修改后 做一次操作
    resolvePromise.then(() => {
      isFlusing = false;
      let copy = [...queue];
      queue.length = 0;
      copy.forEach(job => job());
    });
  }
};
